package com.ruoyi.common.delayQueue;

import java.util.concurrent.Delayed;
import java.util.concurrent.TimeUnit;

/**
 * 延时队列任务 清除屏幕内容
 */
public class ScreenCleanUpDelayed implements Delayed {
    final private Integer directionCode;
    final private long expire;

    /**
     * 构造延时任务
     * @param directionCode 行驶方向
     * @param expire 任务延时时间（ms）
     */
    public ScreenCleanUpDelayed(Integer directionCode, long expire) {
        super();
        this.directionCode = directionCode;
        this.expire = expire + System.currentTimeMillis();
    }

    public Integer getDirectionCode() {
        return directionCode;
    }

    @Override
    public long getDelay(TimeUnit unit) {
        return unit.convert(this.expire - System.currentTimeMillis(), unit);
    }

    @Override
    public int compareTo(Delayed o) {
        long delta = getDelay(TimeUnit.NANOSECONDS) - o.getDelay(TimeUnit.NANOSECONDS);
        return (int) delta;
    }
}
